package hcs.model;

import hcs.interfaces.IHouseSettings;
import hcs.interfaces.StateObservable;

/**
 * Room Settings.
 */
public class RoomSettings extends StateObservable {
	private double StandardPresenceTemp;
	private double StandardAwayTemp;
	private int StandardHeatingTime;
	private int StandardAwayTime;
	private int StandardInsideTime;
	private Room room;
	
	public RoomSettings(Room r) {
		super();
		this.room = r;
		this.setChanged();
	}
	
	/**
	 * Revert the values to their default values.
	 */
	public void revertToDefault() {
		IHouseSettings m = this.room.getHouseController().getHouseSettings();
		StandardPresenceTemp = m.StandardPresenceTemp();
		StandardAwayTemp = m.StandardAwayTemp();
		StandardHeatingTime = m.StandardHeatingTime();
		StandardAwayTime = m.StandardAwayTime();
		StandardInsideTime = m.StandardInsideTime();
	}
	
	/**
	 * 
	 * @return StandardPresenceTemp
	 * @see System documentation
	 */
	public double getStandardPresenceTemp() {
		return this.StandardPresenceTemp;
	}
	
	/**
	 * Set StandardPresenceTemp
	 * @see System documentation
	 */
	public void setStandardPresenceTemp(double t) {
		this.StandardPresenceTemp = t;
		this.setChanged();
	}
	
	/**
	 * 
	 * @return StandardAwayTemp
	 * @see System documentation
	 */
	public double getStandardAwayTemp() {
		return this.StandardAwayTemp;
	}
	
	/**
	 * 
	 * set StandardAwayTemp
	 * @see System documentation
	 */
	public void setStandardAwayTemp(double t) {
		this.StandardAwayTemp = t;
		this.setChanged();
	}
	
	/**
	 * 
	 * @return StandardHeatingTime
	 * @see System documentation
	 */
	public int getStandardHeatingTime() {
		return this.StandardHeatingTime;
	}
	
	/**
	 * Set StandardHeatingTime
	 * @throws InvalidTimeException if the requested time is not greater than 5 minutes over standard inside time.
	 * @see System documentation
	 */
	public void setStandardHeatingTime(int t) throws InvalidTimeException {
		if (t-getStandardInsideTime()<5) {
			throw new InvalidTimeException(t,getStandardInsideTime());
		}
		this.StandardHeatingTime = t;
		this.setChanged();
	}
	
	/**
	 * 
	 * @return StandardAwayTime
	 * @see System documentation
	 */
	public int getStandardAwayTime() {
		return this.StandardAwayTime;
	}
	
	/**
	 * 
	 * set StandardAwayTime
	 * @see System documentation
	 */
	public void setStandardAwayTime(int t) {
		this.StandardAwayTime = t;
		this.setChanged();
	}
	
	/**
	 * 
	 * @return StandardInsideTime
	 * @see System documentation
	 */
	public int getStandardInsideTime() {
		return this.StandardInsideTime;
	}
	
	/**
	 * Set StandardInsideTime
	 * @see System documentation
	 */
	public void setStandardInsideTime(int t) {
		this.StandardInsideTime = t;
		this.setChanged();
	}
	
	/**
	 * @return settings serialized in html, i.e.
	 * "<html><strong>" + this.room.getName() + " settings</strong><br>" + 
	 * "StandardPresenceTemp: " + StandardPresenceTemp + "<br>" +
	 * ....
	 * "</html>"
	 * 
	 * without newlines
	 */
	public String toString() {
		StringBuffer ret = new StringBuffer();
		ret.append("<html><strong>" + this.room.getName() + " settings</strong><br>");
		ret.append("StandardPresenceTemp: " + String.format("%.1f", StandardPresenceTemp) + "<br>");
		ret.append("StandardAwayTemp: " + String.format("%.1f", StandardAwayTemp) + "<br>");
		ret.append("StandardHeatingTime: " + StandardHeatingTime + "<br>");
		ret.append("StandardAwayTime: " + StandardAwayTime + "<br>");
		ret.append("StandardInsideTime: " + StandardInsideTime + "<br>");
		ret.append("</html>");
		return ret.toString();
	}

	public Room getRoom() {
		return room;
	}
};
